/* Copyright 2009
 *
 * This program and the accompanying materials
 * are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * Contributors:
 * 	   IBM Corporation - initial API and implementation for JDT/DLTK
 *     Sean W. Quinn - initial adoption for use with PHP from various sources.
 */
package org.eclipse.php.internal.ui.preferences;

import org.eclipse.dltk.ui.formatter.AbstractFormatterPreferencePage;
import org.eclipse.dltk.ui.preferences.PreferenceKey;
import org.eclipse.dltk.ui.text.IColorManager;
import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.php.internal.core.documentModel.partitioner.PHPPartitionTypesExt;
import org.eclipse.php.internal.core.project.PHPNature;
import org.eclipse.php.internal.ui.PHPUiPlugin;
import org.eclipse.php.internal.ui.PHPUiPluginExt;
import org.eclipse.ui.texteditor.ITextEditor;

/**
 * <p>
 * This class represents a preference page that is contributed to the
 * Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>, we
 * can use the field support built into JFace that allows us to create a page
 * that is small and knows how to save, restore and apply itself.
 * </p>
 * <p>
 * This page is used to modify preferences only. They are stored in the
 * preference store that belongs to the main plug-in class. That way,
 * preferences can be accessed directly via the preference store.
 * </p>
 *
 * @author Sean W. Quinn (swquinn@gmail.com)
 */
@SuppressWarnings("restriction")
public class PHPCodeFormatterPreferencePage extends AbstractFormatterPreferencePage {

  /** The preference [page] ID. */
  public static final String PREF_ID = "org.eclipse.php.ui.preferences.PHPCodeFormatterPreferencePage"; //$NON-NLS-1$

  /** The property [page] ID. */
  public static final String PROP_ID = "org.eclipse.php.ui.propertyPages.PHPCodeFormatterPreferencePage"; //$NON-NLS-1$

  private static final PreferenceKey FORMATTER = new PreferenceKey(PHPUiPlugin.ID,
      PHPPreferenceConstants.FORMATTER_ID);

  /**
   * {@inheritDoc}
   */
  @Override
protected String getPreferencePageId() {
    return PREF_ID;
  }

  /**
   * {@inheritDoc}
   */
  @Override
protected String getPropertyPageId() {
    return PROP_ID;
  }

  @Override
  protected String getNatureId() {
    return PHPNature.ID;
  }

  @Override
  protected PreferenceKey getFormatterPreferenceKey() {
    return FORMATTER;
  }

  @Override
  protected IDialogSettings getDialogSettings() {
    return PHPUiPluginExt.getDefault().getDialogSettings();
  }

  @Override
  protected ScriptSourceViewerConfiguration createSimpleSourceViewerConfiguration(IColorManager colorManager,
      IPreferenceStore preferenceStore, ITextEditor editor, boolean configureFormatter) {
    return new SimplePHPSourceViewerConfiguration(colorManager, preferenceStore, editor,
        PHPPartitionTypesExt.PHP_PARTITIONING, configureFormatter);
  }

  @Override
  protected void setPreferenceStore() {
    setPreferenceStore(PHPUiPluginExt.getDefault().getPreferenceStore());
  }
}